<template>
	<view class="eva-list">
		<NavBar title="评价列表" bgc="#fff"/>
		<Evaluate :is-title="false" @tapType="tapType" :evaList="evaList"/>
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import { onLoad, onReachBottom } from '@dcloudio/uni-app'
	import NavBar from '@/components/NavBar.vue';
	import Evaluate from '@/components/Evaluate.vue';
	import { GetGoodsEvaApi } from '@/service/index.js'
	const id = ref()
	const type = ref(0)
	const page = ref(1)
	const pageSize = ref(15)
	const total = ref(0)
	const evaList = ref([])
	const tapType = (e) => {
		type.value = e
		page.value = 1
		evaList.value = []
		getEvaList()
	} 
	const getEvaList = () => {
		const params = {
			page: page.value,
			page_size: pageSize.value,
			goods_id: id.value,
			search_type: type.value
		}
		GetGoodsEvaApi(params).then(res => {
			total.value = res.total
			evaList.value.push(...res.data)
		})
	}
	onLoad((e) => {
		const { goodsId } = e
		id.value = goodsId
		getEvaList()
	})
	onReachBottom(() => {
		if(page.value*pageSize.value>=total.value) return
		page.value = page.value + 1
		getEvaList()
	})
</script>

<style lang="scss" scoped>
	.eva-list {
		min-height: 100vh;
		background-color: #fff;
	}
</style>
